var webdir='http://www.2admin.co.cc';
var limit=10;
var start=0;

var pageselect=1;
$(document).ready(function() {

getforum();

}); 


function getforum()
{
    
    $.post(webdir+'/ajax.php',{functioncall:'getforum',start:start,limit:limit} ,function(data) {
    var view;
     var myObject = eval('(' + data + ')');
            
             $('#forumtbody').html('');
            if(myObject.count>0)
            { 
            for (variable in myObject.data)
             {   
          //   alert(variable) ;
             var obj = myObject.data[variable]; 
             
             if(obj.view=== null)
             {
                 view=0;
             }else
             {
                 view=obj.view;
             }
             var strtr='<tr><td><a href="forum-detail.html?foid='+obj.foid+'">'+obj.ftitle+'</a></td><td>'+obj.name+'</td><td>'+view+'</td><td>'+obj.countans+'</td><td>'+obj.createdate+'</td><td>'+obj.updatedate+'</td></tr>';
             $('#forumtbody').append(strtr);
             
             }
             
             var totalpage=Math.ceil((myObject.count)/(limit) );
             
             $('.pagebarUTH').html('');
             $('.pagebarUTH').append('<a href="javascript:;" title="Seite 2">จำนวนกระทู้ '+myObject.count+'</a>&nbsp;');
             if(totalpage!=1)
             {
                var previous= totalpage-1;
                 $('.pagebarUTH').append('<a href="javascript:changepage('+previous+');" title="Seite 2"><< Previous</a>&nbsp;');
             }
             
             for(var i=1;i<=totalpage;i++)
             {
                 if(i==pageselect)
                 {
                  var strlink='<span class="this-page">'+i+'</span>';   
                 }else
                 {
                  var strlink='<a href="javascript:changepage('+i+');" title="Seite 2">'+i+'</a>';    
                 }
                 $('.pagebarUTH').append(strlink);
                 
             }
             
             if(totalpage!=1)
             {
                var next= totalpage+1;
                 $('.pagebarUTH').append('<a href="javascript:changepage('+next+');" title="Seite 2">Next >></a>');
                 $('.pagebarUTH').append('<a href="javascript:changepage('+totalpage+');" title="Seite 2">Last</a>');
             }
             
             
  
            }
     
});
    
}
function changepage(page)
{
    start=(10*(page-1));
    getforum();
}